 <?php
//* UCS API v. 3.0 *//
//* http://www.unlockcodesource.com remote interface class
//* Copyright unlockcodesource.com 2011 *//
//* if you have any questions or would like to report a bug please contact techsupport@unlockcodesource.com *//

//* include xml serializer and unserializer functions
require("xmlUCS.php");

class UCS {
	var $username;
	var $pass;
	var $apikey;
	var $response;
	
	function UCS (){
		$this->username = "yoannyrj@gmail.com";
		$this->pass = "*#06#masterU2012";
		$this->apikey = "EXGzHk-IXCvqm-JqAkLI-Sq7jlR-PYytjf-mAWwie";
	}
	
	
	function action ($action, $params = array()) {

		$datarequest['API']['username'] = $this->username;
		$datarequest['API']['pass'] = $this->pass;
		$datarequest['API']['key']= $this->apikey;
		$datarequest['API']['action'] = $action;
		
		switch ($action) {
			case "get_accountinfo":
				$datarequest['API']['action'] = "get_accountinfo";
			break;
			
			case "get_unlocktools":
				(isset($params['method_id'])) ? $datarequest['API']['method_id'] = $params['method_id'] : $datarequest['API']['method_id'] = NULL;
				(isset($params['cust_id'])) ? $datarequest['API']['cust_id'] = $params['cust_id'] : $datarequest['API']['cust_id'] = NULL;
				$datarequest['API']['action'] = "get_unlocktools";		
			break;
			
			case "get_instructions":
				(isset($params['instruction_id'])) ? $datarequest['API']['instruction_id'] = $params['instruction_id'] : $datarequest['API']['instruction_id'] = NULL;
				$datarequest['API']['action'] = "get_instructions";			
			break;
			
			case "submit_order":
				(isset($params['imei'])) ? $datarequest['API']['imei'] = $params['imei'] : $datarequest['API']['imei'] = NULL;
				(isset($params['phonemake_id'])) ? $datarequest['API']['phonemake_id'] = $params['phonemake_id'] : $datarequest['API']['phonemake_id'] = NULL;																																
				(isset($params['model'])) ? $datarequest['API']['model'] = $params['model'] : $datarequest['API']['model'] = "";
				(isset($params['tool_id'])) ? $datarequest['API']['tool_id'] = $params['tool_id'] : $datarequest['API']['tool_id'] = 0;
				(isset($params['notes'])) ? $datarequest['API']['notes'] = $params['notes'] : $datarequest['API']['notes'] = "";
				(isset($params['cust_id'])) ? $datarequest['API']['cust_id'] = $params['cust_id'] : $params['cust_id'] = NULL;	
				(isset($params['params'])) ? $datarequest['API']['params'] = $params['params'] : $params['params'] = NULL;
			break;
			
			case "get_orderID":
				(isset($params['orderID'])) ? $datarequest['API']['orderID'] = $params['orderID'] : $datarequest['API']['orderID'] = NULL;
				$datarequest['API']['action'] = "get_orderID";
		
			break;
			
			case "get_imei":
				(isset($params['imei'])) ? $datarequest['API']['imei'] = $params['imei'] : $datarequest['API']['imei'] = NULL;
				$datarequest['API']['action'] = "get_imei";
			break;
			
			case "VIP_authuser":
				(isset($params['vipuser'])) ? $datarequest['API']['vipuser'] = $params['vipuser'] : $datarequest['API']['vipuser'] = NULL;
				(isset($params['vippass'])) ? $datarequest['API']['vippass'] = $params['vippass'] : $datarequest['API']['vippass'] = NULL;
				$datarequest['API']['action'] = "VIP_authuser";					
			break;
		
			case "VIP_orderhistory":
				(isset($params['vip_id'])) ? $datarequest['API']['vip_id'] = $params['vip_id'] : $datarequest['API']['vip_id'] = NULL;
				$datarequest['API']['action'] = "VIP_orderhistory";				
			break;
			
			case "VIP_balance":	
				(isset($params['vip_id'])) ? $datarequest['API']['vip_id'] = $params['vip_id'] : $datarequest['API']['vip_id'] = NULL;
				$datarequest['API']['action'] = "VIP_balance";
			break;
			
			case "VIP_pending":
				(isset($params['vip_id'])) ? $datarequest['API']['vip_id'] = $params['vip_id'] : $datarequest['API']['vip_id'] = NULL;
				$datarequest['API']['action'] = "VIP_pending";		
			break;
			
			case "VIP_changepass":
				(isset($params['vip_id'])) ? $datarequest['API']['vip_id'] = $params['vip_id'] : $datarequest['API']['vip_id'] = NULL;
				$datarequest['API']['action'] = "VIP_changepass";
				(isset($params['old_pass'])) ? $datarequest['API']['old_pass'] = $params['old_pass'] : $datarequest['API']['old_pass'] = NULL;
				(isset($params['new_pass'])) ? $datarequest['API']['new_pass'] = $params['new_pass'] : $datarequest['API']['new_pass'] = NULL;
			break;
			
			case "VIP_getorder":
			break;
			
						
			case "get_RequiredParams":
				(isset($params['tool_id'])) ? $datarequest['API']['tool_id'] = $params['tool_id'] : $datarequest['API']['tool_id'] = NULL;
			break;
			
			case "get_SortedMethodList":
				$datarequest['API']['action'] = "get_SortedMethodList";
				(isset($params['vip_id'])) ? $datarequest['API']['vip_id'] = $params['vip_id'] : $datarequest['API']['vip_id'] = NULL;
			break;
		}
		
		$this->response = $this->sendQuery($datarequest);

	}
	
	function sendQuery($data) {
		//*change array to xml *//
		//print_r($data);
		$xmlrequest = XML_serialize($data);
		$xmlrequest = 'data='.$xmlrequest;
		$timeout = 90;
		$url = "http://www.unlockcodesource.com/API_v2/ucs_apiv3.php"; //XML service API address
		//$url = "http://24.85.147.86/ucsv3/API_v2/ucs_apiv2.php";
		//$url = "http://www.unlockcodesource.com/API_v2/ucs_mobileapi.php";
		//$url = "http://24.85.147.86/ucsv3/API_v2/ucs_mobileapi.php";
		$ch = curl_init(); //initiate the curl session
		curl_setopt($ch, CURLOPT_URL, $url); //set to url to post to
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // tell curl to return data in a variable
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlrequest); // post the xml
		curl_setopt($ch, CURLOPT_TIMEOUT, 10); // set timeout in seconds
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
		$result['xml'] = curl_exec($ch);
		curl_close ($ch);
		//* set the xml as array *//
		$result['data'] = XML_unserialize($result['xml']); 
		return $result;
	}
	
}
?>